//
//  LXSearchTextField.m
//  微博
//
//  Created by imera on 15/9/18.
//  Copyright (c) 2015年 imera. All rights reserved.
//

#import "LXSearchTextField.h"

@implementation LXSearchTextField

+ (instancetype)LXSearchTextField
{
    return [[self alloc]init];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if(self){
        self.background = [UIImage resizeWithName:@"searchbar_textfield_background"];
        self.bounds = CGRectMake(0, 0, 300, 30);
        self.font = [UIFont systemFontOfSize:14];
        
        //设置提醒文字及字体
        NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
        self.attributedPlaceholder = [[NSAttributedString alloc]initWithString:@"搜索" attributes:attrs];
        
        //放大镜图标
        UIImageView *icon = [[UIImageView alloc]initWithImage:[UIImage imageWithName:@"searchbar_textfield_search_icon"]];
        icon.bounds = CGRectMake(0, 0, 30, self.frame.size.height);
        icon.contentMode = UIViewContentModeCenter;
        
        //显示左边图标
        self.leftViewMode = UITextFieldViewModeAlways;
        self.leftView = icon;
        
        //设置右下角键盘样式
        self.returnKeyType = UIReturnKeySearch;
        self.enablesReturnKeyAutomatically = YES;
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    //设置放大镜图标frame
    self.leftView.frame = CGRectMake(0, 0, 30, self.frame.size.height);
}
@end
